<template>
	<view class="draw-cash">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<template #top>
				<view class="tabbar">
					<view class="tabbar-item" :class="{'tabbar-item-active': currentTab === 0}" @click="changeTab(0)">充值失败</view>
					<view class="tabbar-item" :class="{'tabbar-item-active': currentTab === 1}" @click="changeTab(1)">充值成功</view>
				</view>
			</template>
			<view class="cash-de">
			</view>
			<view class="card">
				<view class="card-item" v-for="(item, index) of dataList" :key="index">
					<view class="card-item-content">
						<view class="card-item-content-text">
							<view>订单号:{{ item.order_id || '-' }}</view>
							<view>充值金额: {{ item.total_price }}</view>
							<view>套餐次数: {{ item.total_count }}</view>
							<view>赠送次数: {{ item.send_count }}</view>
							<view>充值时间: {{ item.create_time }}</view>
							<view>充值状态: {{ item.pay_status === '0' ? '充值失败': '成功'  }}</view>
							<view>类型: {{ item.type === '1' ? '充值' : '赠送' }}</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	import request from "@/api/request.js"
	import dayJS from 'dayjs'
	export default {
		data() {
			return {
				currentTab: 0, // 默认选中第一个选项
				dataList: [],
				withdrawalDto: {
					token: '',
					pay_status: 0,
					page: 1,
					page_size: 10
				}
			}
		},
		onLoad() {
			this.withdrawalDto.token = uni.getStorageSync('token')
		},
		methods: {
			changeTab(index) {
				this.currentTab = index; // 更新当前选项的值
				this.withdrawalDto.pay_status = index
				this.$refs.paging.reload()
			},

			queryList(page, page_size) {
				uni.showLoading({
					title: '加载中...'
				})
				const that = this
				this.withdrawalDto.page = page
				this.withdrawalDto.page_size = page_size
				request({
					url: '/kx/Personal/recharge',
					data: this.withdrawalDto,
					method: 'POST',
					successCb(res) {
						uni.hideLoading()
						const {
							data: tempData
						} = res.data
						if (tempData) {
							res.data.data.forEach(item => {
								item.create_time = dayJS(item.create_time * 1000).format(
									'YYYY-MM-DD HH:mm:ss')
							})
						}
						that.$refs.paging.complete(res.data.data);
					},
					failCb() {
						uni.hideLoading()
						that.$refs.paging.complete(false);
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar {
		display: flex;
		justify-content: space-around;
		margin: 24rpx 32rpx 12rpx 32rpx;

		&-item {
			width: 170rpx;
			height: 48rpx;
			border-radius: 30rpx;
			background: #fff;
			color: #8D8D8D;
			text-align: center;
			line-height: 48rpx;
			font-size: 28rpx;
			font-weight: 500;

			&-active {
				background: #FF8732;
				color: #fff;
			}
		}
	}

	.draw-cash {
		width: 100%;
		background: #F4F4F4;
		height: 100vh;
	}

	.cash-ca {
		display: flex;
		justify-content: space-around;
		font-size: 30rpx;
		padding: 20rpx;
		background-color: $uni-bg-color;
		margin-bottom: 20rpx;

		.selected {
			font-size: 36rpx;
			font-weight: bold;
		}
	}

	.cash-de {
		display: flex;
		flex-direction: column;
		align-items: center;
		color: #cccccc;
		font-size: 36rpx;
	}

	.card {
		&-item {
			margin: 12rpx auto;
			width: 680rpx;
			padding: 24rpx 0;
			background: $uni-bg-color;
			border-radius: 20rpx;

			&-content {
				@include layout;
				padding: 0 36rpx 0 36rpx;

				&-text {
					view {
						&:nth-child(1) {
							font-weight: 500;
							font-size: 28rpx;
							color: #3D3D3D;
						}

						&:nth-child(2) {
							margin-top: 12rpx;
							font-size: 24rpx;
							color: #8D8D8D;
						}

						&:nth-child(3) {
							font-size: 24rpx;
							color: #8D8D8D;
						}
						
						&:nth-child(4) {
							font-size: 24rpx;
							color: #8D8D8D;
						}
						
						&:nth-child(5) {
							font-size: 24rpx;
							color: #8D8D8D;
						}
						
						&:nth-child(6) {
							font-size: 24rpx;
							color: #8D8D8D;
						}
						
						&:nth-child(7) {
							font-size: 24rpx;
							color: #8D8D8D;
						}
						
						&:nth-child(8) {
							font-size: 24rpx;
							color: #8D8D8D;
						}
					}
				}
			}
		}
	}
</style>